package com.itheima;

import com.itheima.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import sun.rmi.runtime.Log;

@SpringBootApplication
public class Springmvc02Application implements WebMvcConfigurer {
    public static void main(String[] args) {
        SpringApplication.run(Springmvc02Application.class, args);
    }

    @Autowired
    private LoginInterceptor loginInterceptor;
    //添加(注册)拦截器的方法
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //addPathPatterns():添加拦截路径
        registry.addInterceptor(loginInterceptor).addPathPatterns("/brand/**");

        //需求：访问页面的时候不要执行拦截器
        //registry.addInterceptor(loginInterceptor)
        //        .addPathPatterns("/**")
        //        .excludePathPatterns("/success.html","/upload.html","/user/**");  //排除某些路径不拦截
    }
}
